package com.zty.xiaomi.server.Mapper;

import com.zty.xiaomi.server.Entity.Tribunal.Tribunal;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public interface TribunalMapper {
    @Insert("insert into tribunal(user_name,store_id,good_id,user_vote,store_vote,result,status,orderNo,tribunal_describe,create_time)" +
            " values(#{user_name},#{store_id},#{good_id},#{user_vote},#{store_vote}" +
            ",#{result},#{status},#{orderNo},#{tribunal_describe},#{create_time})")
    @Options(useGeneratedKeys = true, keyProperty = "tribunal_id")
    int addTribunal(Tribunal tribunal);

    @Select("select tribunal_id, user_name,store_id,good_id,orderNo,user_vote,store_vote,result,status,tribunal_describe from" +
            " tribunal where status = #{status}")
    List<Tribunal> getTribunalsByStatus(int status);

    @Update("update tribunal set user_vote = user_vote + 1 where tribunal_id = #{tribunal_id}")
    int updateTribunalUserVoteById(int tribunal_id);

    @Update("update tribunal set store_vote = store_vote + 1 where tribunal_id = #{tribunal_id}")
    int updateTribunalStoreVoteById(int tribunal_id);

    @Select("select tribunal_id, user_name,store_id,good_id,user_vote,store_vote,result" +
            ",status, orderNo,tribunal_describe from tribunal where tribunal_id = #{tribunal_id}")
    Tribunal getTribunalDetailById(int tribunal_id);

    @Update("update tribunal set result = #{result}, status = #{status} where tribunal_id = #{tribunal_id}")
    int updateTribunalResultAndStatusById(int tribunal_id, String result, int status);

    //法庭关闭
    @Update("update tribunal set  status =1 where tribunal_id = #{tribunal_id}")
    int updateTribunalStatusById(int tribunal_id);

    @Select("select tribunal_id, user_name,store_id,good_id,user_vote,store_vote,result" +
            ",status, orderNo,tribunal_describe from tribunal where user_name = #{user_name}")
    List<Tribunal> getMyTribunalByUserName(String user_name);

    @Select("select * from  tribunal")
    List<Tribunal> getAllTribunal();

}
